﻿namespace _01_Tower
{
    internal class HPBar
    {
        Hero hero;
        int maxHp;
        int x, y;

        public HPBar(int x, int y, int maxHp,Hero hero)
        {
            this.x = x;
            this.y = y;
            this.hero = hero;
            hero.hp = maxHp;
            this.maxHp = maxHp;
        }

        public void SetHp(int hp)
        {
            hero.hp = hp;
            if (hero.hp > maxHp)
            {
                hero.hp = maxHp;
            }
            if (hero.hp < 0)
            {
                hero.hp = 0;
            }
            Clear();
            Render();
        }

        public void Clear()
        {
            for (int i = 0; i < 20; i++)
            {
                Utility.MyPrint(" ", x + 3 + i, y,ConsoleColor.White, ConsoleColor.White);
                Utility.MyPrint($"          ", x + 24, y, ConsoleColor.White);
            }
        }

        public void Render()
        {
            Utility.MyPrint("HP: ", x, y);
            for (int i = 0; i < hero.hp * 20 / maxHp; i++)
            {
                Utility.MyPrint(" ", x + 3 + i, y, ConsoleColor.Red,ConsoleColor.Red);
            }
            Utility.MyPrint($"{hero.hp}/{maxHp}", x + 24, y,ConsoleColor.White);
        }
    }
}
